var prefix = jsctx + "/ugsMemberSuperLevel";

var buyRecord = (function () {
    function init() {
        setTimeout(function () {//防止先于-读取缓存执行
            load();
        },10)
    };

    $('#exampleTable').on('load-success.bs.table', function (e, data) {
        if (data.total && !data.rows.length) {
            $('#exampleTable').bootstrapTable('selectPage').bootstrapTable('refresh');
        }
    });

    function load() {
        $('#exampleTable')
            .bootstrapTable(
                {
                    method: 'get',
                    url: prefix + "/listPageBuyRecord",
                    iconSize: 'outline',
                    toolbar: '#exampleToolbar',
                    striped: false,
                    dataType: "json",
                    pagination: true,
                    singleSelect: false,
                    cache: false,
                    pageSize: 20,
                    pageList: [20],
                    pageNumber: 1,
                    sidePagination: "server",
                    queryParams: function (params) {
                        return {
                            limit: params.limit,
                            offset: (params.offset / params.limit) + 1,
                            memberId: $("#memberId").val().trim(),
                            beginTime: $("#beginTime").val().trim(),
                            memberId: $("#memberId").val().trim(),
                        };
                    },
                    columns: [
                        {
                            title: '#', field: '',
                            formatter: function (value, row, index) {
                                return index + 1;
                            }
                        },
                        {field: 'nickname', title: '昵称', align: 'left'},
                        {field: 'mobile', title: '手机号', align: 'left'},
                        {
                            field: 'superOrderType', title: '获得途径',
                            align: 'left',
                            formatter: function (value, row, index) {
                                if (value == '0') {
                                    return '购买'
                                } else if (value == '1') {
                                    return '赠送 '
                                }
                            }
                        },
                        {
                            field: 'superCardType', title: '类型',
                            align: 'left',
                            formatter: function (value, row, index) {
                                if (value == '0') {
                                    return '月卡'
                                } else if (value == '1') {
                                    return '季卡 '
                                } else if (value == '2') {
                                    return '年卡 '
                                }
                            }
                        },
                        {field: 'beginTime', title: '有效期开始时间', align: 'left'},
                        {field: 'endTime', title: '有效期结束时间', align: 'left'},
                        {
                            field: '', title: '支付状态', align: 'center',
                            formatter: function (value, row, index) {
                                if (row.superOrderType == '0') {
                                    if (row.status == '0') {
                                        return '未支付'
                                    } else if (row.status == '1') {
                                        return '已支付'
                                    }
                                } else if (value == '1') {
                                    return ''
                                }
                            }
                        },
                    ]
                });
    }

    function reLoad() {
        $('#exampleTable').bootstrapTable('refresh');
    }


    function goBack() {
        window.history.back();
    }


    return {
        init: init,
        goBack: goBack,
        reLoad: reLoad
    }
})();
